package com.gg.haoqi.utils;

import android.content.Context;

import com.gg.haoqi.R;
import com.nostra13.universalimageloader.cache.disc.DiskCache;
import com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;


public class ImageLoaderUtils {

    /**
     * UIL全局配置图片加载框架
     */
    public static void configGolbalImageLoader(Context context) {
        ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context);
        DiskCache diskCache = new LimitedAgeDiskCache(FileUtil.getImageCache(context), 50 * 1024 * 1024);
        builder.diskCache(diskCache);  //磁盘缓存
        builder.diskCacheFileNameGenerator(new Md5FileNameGenerator());  //加密
        builder.memoryCacheSize(4 * 1024 * 1024);   //内存缓存
        builder.threadPoolSize(4);
        ImageLoader.getInstance().init(builder.build());
    }

    public static DisplayImageOptions getDisplayImageLoader() {
        DisplayImageOptions.Builder builder = new DisplayImageOptions.Builder();
        //配置加载图片错误时候显示的图片
        builder.showImageOnFail(R.mipmap.ic_launcher);
        builder.showImageOnLoading(R.mipmap.ic_launcher);
        builder.cacheInMemory(true);
        builder.cacheOnDisk(true);
        return builder.build();
    }


}
